﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Extensil.Common
{
    public class UserForm : Form
    {
        UserForm _containerForm;
        public UserForm ContainerForm
        {
            get
            {
                if(_containerForm == null)
                {
                    try
                    {
                        return (UserForm)this.ParentForm;
                    }
                    catch(Exception exc)
                    {
                        return null;
                    }
                }
                else
                    return _containerForm;
            }
            set
            {
                _containerForm = value;
            }
        }
        public Form SuperForm
        {
            get
            {
                UserForm frm = this;
                while(frm.ContainerForm != null)
                    frm = frm.ContainerForm;
                return frm;
            }
        }
        public Form GetParentForm(string formName)
        {
            Form frm = this.ParentForm;
            if(frm == null)
                return null;
            while(frm.Name != formName)
                frm = frm.ParentForm;
            return frm;
        }
    }
}
